package com.sip.dbadapter.dao.domain;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 *
 */
@Entity
@Table(name = "SYSTEM_INFO")
public class SystemInfo implements Serializable {

    private static final long serialVersionUID = 1L;

    private Long id;

    private String systemName;

    private Set<ApiDefinition> apiDefinitionSet = new HashSet<ApiDefinition>();

    public SystemInfo() {

        id = Long.valueOf(0);
    }

    @Id
    @Column(name = "SYSTEM_ID", unique = true, nullable = false)
    @GeneratedValue
    public Long getId() {

        return id;
    }

    @Column(name = "SYSTEM_NAME", nullable = false)
    public String getSystemName() {

        return systemName;
    }

    @JoinColumn(name = "SYSTEM_ID", referencedColumnName = "SYSTEM_ID")
    @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
    // , mappedBy = "systemInfo"
    public Set<ApiDefinition> getApiDefinitionSet() {

        return apiDefinitionSet;
    }

    public void setId(Long id) {

        this.id = id;
    }

    public void setSystemName(String systemName) {

        this.systemName = systemName;
    }

    public void setApiDefinitionSet(Set<ApiDefinition> apiDefinitionSet) {

        this.apiDefinitionSet = apiDefinitionSet;
    }

    @Override
    public int hashCode() {

        int result = 0;
        result = (int) (31 * result + id);
        result = 31 * result + (systemName != null ? systemName.hashCode() : 0);

        return result;
    }

    @Override
    public boolean equals(Object other) {

        if (this == other)
            return true;

        if (other == null || (this.getClass() != other.getClass())) {
            return false;
        }

        SystemInfo record = (SystemInfo) other;
        return (this.id == record.id) && (this.systemName != null && systemName.equals(record.systemName));

    }

}
